import { Result } from "~/models/HomePage/index";

export function Http(instance: any, method: string, url: string, data: Object) {
  let param;
  if (method.toLocaleUpperCase() === "GET") {
    data = param;
  }
  const _this = instance;
  return new Promise((resolve, reject) => {
    _this
      .$axios({
        url,
        method,
        param
      })
      .then(res => {
        let result: Result = {
          status: 0,
          data: {}
        };
        if (res.data && res.data.code === 200) {
          result.status = 0;
          result.data = res.data.data;
          resolve(result);
        } else {
          result.status = 1;
          resolve(result);
        }
      });
  });
}
